package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("api/apilog")
public @caption("API日志") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_api_log") class SrvApiLog implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sal_id")    @primary  @notnull  @note("  ") Long salId;// 主键 非空     
	private @caption("调用应用") @column("sal_client")     @notnull  @relate("$salClient") @RelateClass(SrvApiClient.class)  @note("  ") Long salClient;// 非空     
 	private transient SrvApiClient $salClient;//关联对象[API客户端]
	private @caption("调用API") @column("sal_api")     @notnull  @relate("$salApi") @RelateClass(SrvApi.class)  @note("  ") String salApi;// 非空    select * from srv_api where 1=1 
 	private transient SrvApi $salApi;//关联对象[API接口]
	private @caption("调用参数") @column("sal_params") @like    @notnull  @note("  ") String salParams;// 非空     
	private @caption("返回数据") @column("sal_return") @like    @notnull  @note("  ") String salReturn;// 非空     
	private @caption("添加时间") @column("sal_invoke_time")     @notnull  @note("  ") Date salInvokeTime;// 非空     
	private @caption("状态") @column("sal_status")     @notnull  @note(" 1:默认  ") Short salStatus;// 非空 1:默认     
	 
	//默认构造函数
	public SrvApiLog(){ 
	
	}
	
	//主键构造函数
	public SrvApiLog(Long id){
		this.salId = id;
	}
	
	/**所有字段构造函数 
	 SrvApiLog(
	 	Utils.getLong("salClient")//调用应用 [非空]
	 	,Utils.getString("salApi")//调用API [非空]
	 	,Utils.getString("salParams")//调用参数 [非空]
	 	,Utils.getString("salReturn")//返回数据 [非空]
	 	,Utils.getDate("salInvokeTime")//添加时间 [非空]
	 	,Utils.getShort("salStatus")//状态 [非空]
	 )
	**/
	public SrvApiLog(Long salClient,String salApi,String salParams,String salReturn,Date salInvokeTime,Short salStatus){
		this.salClient=salClient;
		this.salApi=salApi;
		this.salParams=salParams;
		this.salReturn=salReturn;
		this.salInvokeTime=salInvokeTime;
		this.salStatus=salStatus;
	}
	
	//设置非空字段
	public SrvApiLog setNotNull(Long salClient,String salApi,String salParams,String salReturn,Date salInvokeTime,Short salStatus){
		this.salClient=salClient;
		this.salApi=salApi;
		this.salParams=salParams;
		this.salReturn=salReturn;
		this.salInvokeTime=salInvokeTime;
		this.salStatus=salStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvApiLog salId(Long salId){
		this.salId = salId;
		this.setSeted(F.salId);
		return this;
	}
	/** 调用应用 [非空] [SrvApiClient]      **/
	public SrvApiLog salClient(Long salClient){
		this.salClient = salClient;
		this.setSeted(F.salClient);
		return this;
	}
	/** 调用API [非空] [SrvApi]     select * from srv_api where 1=1 **/
	public SrvApiLog salApi(String salApi){
		this.salApi = salApi;
		this.setSeted(F.salApi);
		return this;
	}
	/** 调用参数 [非空]       **/
	public SrvApiLog salParams(String salParams){
		this.salParams = salParams;
		this.setSeted(F.salParams);
		return this;
	}
	/** 返回数据 [非空]       **/
	public SrvApiLog salReturn(String salReturn){
		this.salReturn = salReturn;
		this.setSeted(F.salReturn);
		return this;
	}
	/** 添加时间 [非空]       **/
	public SrvApiLog salInvokeTime(Date salInvokeTime){
		this.salInvokeTime = salInvokeTime;
		this.setSeted(F.salInvokeTime);
		return this;
	}
	/** 状态 [非空]   1:默认     **/
	public SrvApiLog salStatus(Short salStatus){
		this.salStatus = salStatus;
		this.setSeted(F.salStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvApiLog clone(){
		SrvApiLog clone = new SrvApiLog();
		clone.salClient=this.salClient;
		clone.salApi=this.salApi;
		clone.salParams=this.salParams;
		clone.salReturn=this.salReturn;
		clone.salInvokeTime=this.salInvokeTime;
		clone.salStatus=this.salStatus;
		return clone;
	}
	
	
	/**
	 * 根据ID取API日志
	 * @param id
	 * @return
	 */
	public static @api SrvApiLog get(Long id){		
		return getSrvApiLogById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.salId = id;
	}
	
	/**
	 * 获取所有API日志
	 * @return
	 */
	public static @api List<SrvApiLog> list(Map params,Integer size){
		return getSrvApiLogList(params,size);
	}
	/**
	 * 获取API日志分页
	 * @return
	 */
	public static @api Page<SrvApiLog> page(Integer page,Integer size,Map params){
		return getSrvApiLogPage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取API日志
	 * @param params
	 * @return
	 */
	public static @api SrvApiLog Get(Map params){
		return getSrvApiLog(params);
	}
	/**
	 * 获取API日志数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvApiLogCount(params);
	}
	/**
	 * 获取API日志数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvApiLogEval(eval,params);
	}
	/**
	 * 获取API日志图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvApiLogStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取API日志图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvApiLogStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取API日志
	 * @param id
	 * @return
	 */
	public static @api SrvApiLog getSrvApiLogById(Long id){		
		return getSrvApiLogDao().getSrvApiLogById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.salId;
	}
	
	
	/**
	 * 根据ID取API日志的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		if(value==null){
			SrvApiLog srvApiLog = get(id);
			if(srvApiLog!=null){
				String strValue = srvApiLog.getSalId$();
				if(!"SalId".equals("SalId"))
					strValue+="("+srvApiLog.getSalId$()+")";
				value = strValue;
			}else{
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSalId$();
		if(!"SalId".equals("SalId"))
			keyValue+="("+this.getSalId$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询API日志对象
	 * @return
	 */
	public static @api SrvApiLog find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("salId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sal_id = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvApiLog.getSrvApiLog(params);
	}
	
	
	/**
	 * 根据关键字查询API日志
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sal_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("salId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sal_id like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvApiLog> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvApiLog srvApiLog:list){
			Map map = new HashMap();
			map.put("key",srvApiLog.getSalId().toString());
			map.put("value", Utils.js(srvApiLog.getKeyValue()));
			if(bObject==true)
				map.put("object",srvApiLog);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有API日志
	 * @return
	 */
	public static @api List<SrvApiLog> getSrvApiLogList(Map params,Integer size){
		return getSrvApiLogDao().getSrvApiLogList(params,0,size);
	}
	
	/**
	 * 获取API日志分页
	 * @return
	 */
	public static @api Page<SrvApiLog> getSrvApiLogPage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvApiLogDao().getSrvApiLogPage(page, size , params);
	}
	
	/**
	 * 根据查询条件取API日志
	 * @param params
	 * @return
	 */
	public static @api SrvApiLog getSrvApiLog(Map params){
		return getSrvApiLogDao().getSrvApiLog(params);
	}
	
	/**
	 * 保存一个API日志
	 * @param srvApiLog
	 * @return
	 */
	public static @api SrvApiLog saveSrvApiLog(SrvApiLog srvApiLog){
		return getSrvApiLogDao().saveSrvApiLog(srvApiLog);
	}
	
	/**
	 * 根据条件更新API日志
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvApiLogByConfirm(Map values, Map params){
		return getSrvApiLogDao().updateSrvApiLogByConfirm(values,params);
	}
	
	/**
	 * 修改一个API日志
	 * @param srvApiLog
	 * @return
	 */
	public static @api int updateSrvApiLog(SrvApiLog srvApiLog){
		return getSrvApiLogDao().updateSrvApiLog(srvApiLog);
	}
	
	/**
	 * 更新API日志非空字段
	 * @param srvApiLog
	 */
	public static @api int updateSrvApiLog$NotNull(SrvApiLog srvApiLog){
		return getSrvApiLogDao().updateSrvApiLog$NotNull(srvApiLog);
	}
	
	/**
	 * 获取API日志数
	 * @return
	 */
	public static @api Long getSrvApiLogCount(Map params){
		return getSrvApiLogDao().getSrvApiLogCount(params);
	}
		
		
	/**
	 * 获取API日志自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvApiLogEval(String eval,Map params){
		return getSrvApiLogDao().getSrvApiLogEval(eval,params);
	}
	/**
	 * 获取API日志图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvApiLogStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvApiLogDao().getSrvApiLogStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvApiLog.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvApiLog.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvApiLog(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvApiLogDao().updateSrvApiLogByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvApiLog(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvApiLogDao().deleteSrvApiLogByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvApiLogDao().removeSrvApiLogById(id);
	}
	
	
	/**
	 * 保存API日志对象
	 * @param params
	 * @return
	 */
	public SrvApiLog save(){
		if(this.getSalId()!=null)
			getSrvApiLogDao().updateSrvApiLog(this);
		else
			return getSrvApiLogDao().saveSrvApiLog(this);
		return this;
	}
	
	
	/**
	 * 更新API日志对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvApiLogDao().updateSrvApiLog$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getSrvApiLogDao().removeSrvApiLogById(this.getSalId());
		else
			getSrvApiLogDao().deleteSrvApiLogById(this.getSalId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvApiLogDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSalId(){
		if(this.salId!=null){
			return this.salId;
		}
		return this.salId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSalId$(){
		String strValue="";
		 strValue=Utils.string(this.getSalId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSalId$(String strValue){
		if(Utils.empty(strValue)){
			this.salId=null;
			return;
		}
	 	this.salId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSalId(Long salId){
		this.salId = salId;
		this.setSeted(F.salId);
	}
	
	
	
	
	/*******************************调用应用**********************************/	
	/**
	* 调用应用 [非空] [SrvApiClient]     
	**/
	public Long getSalClient(){
		if(this.salClient!=null){
			return this.salClient;
		}
		return this.salClient;
	}
	/**
	* 获取调用应用格式化(toString)
	**/
	public String getSalClient$(){
		String strValue="";
		if(this.getSalClient()!=null){
				strValue+=Utils.string(SrvApiClient.getKeyValue(this.getSalClient()));
		}			
	 	 return strValue;
	}
	/**
	* 根据调用应用反格式化
	**/
	public void setSalClient$(String strValue){
		if(Utils.empty(strValue)){
			this.salClient=null;
			return;
		}
		SrvApiClient item = SrvApiClient.find(strValue);
		if(item!=null){
			this.salClient = Utils.parseLong(item.getSacId());
		}
	}
	
	/**
	* 调用应用 [非空] [SrvApiClient]     
	**/
	public void setSalClient(Long salClient){
		this.salClient = salClient;
		this.setSeted(F.salClient);
	}
	
	
	
	
	/**
	* 获取关联对象[API客户端]
	**/	 			
 	public SrvApiClient get$salClient(){
 		if(this.$salClient!=null)
 			return this.$salClient;
 		com.distribute.framework.model.SrvApiClient srvApiClient = null;
		if(this.getSalClient()!=null){
 			srvApiClient = SrvApiClient.get(this.getSalClient());
 		}
 		return srvApiClient;
	}
	/*******************************调用API**********************************/	
	/**
	* 调用API [非空] [SrvApi]     select * from srv_api where 1=1
	**/
	public String getSalApi(){
		if(this.salApi!=null){
			return this.salApi;
		}
		return this.salApi;
	}
	/**
	* 获取调用API格式化(toString)
	**/
	public String getSalApi$(){
		String strValue="";
			
		if(!Utils.empty(this.getSalApi())){
			List<com.distribute.framework.model.SrvApi> items = com.distribute.framework.model.SrvApi.getSrvApiList(Utils.add("definex","sa_id in ("+Utils.string(this.getSalApi()).replace("#","")+")"),-1);
			for(com.distribute.framework.model.SrvApi item1:items)
				strValue+="["+Utils.string(item1.getSaName$())+"]";
		}
	 	 return strValue;
	}
	/**
	* 根据调用API反格式化
	**/
	public void setSalApi$(String strValue){
		if(Utils.empty(strValue)){
			this.salApi=null;
			return;
		}
			
		String strIds = "";
		for(String strItem:strValue.split(",")){
			SrvApi item = SrvApi.find(strItem);
			if(item!=null){
				strIds+=(strIds.equals("")?"":",")+"#"+item.getSaId()+"#";
			}
		}
		this.salApi = strIds;
	}
	
	/**
	* 调用API [非空] [SrvApi]     select * from srv_api where 1=1
	**/
	public void setSalApi(String salApi){
		this.salApi = salApi;
		this.setSeted(F.salApi);
	}
			
	/**
	* 获取调用API列表
	**/ 			
 	public List<com.distribute.framework.model.SrvApi> get$salApi(){
		if(!Utils.empty(this.getSalApi())){
			return com.distribute.framework.model.SrvApi.getSrvApiList(Utils.add("definex","sa_id in ("+Utils.string(this.getSalApi()).replace("#","")+")"),-1);
		}else
			return new ArrayList();
	}
	
	
	
	
	/*******************************调用参数**********************************/	
	/**
	* 调用参数 [非空]      
	**/
	public String getSalParams(){
		if(this.salParams!=null){
			return this.salParams;
		}
		return this.salParams;
	}
	/**
	* 获取调用参数格式化(toString)
	**/
	public String getSalParams$(){
		String strValue="";
		 strValue=Utils.string(this.getSalParams());
	 	 return strValue;
	}
	/**
	* 根据调用参数反格式化
	**/
	public void setSalParams$(String strValue){
		if(Utils.empty(strValue)){
			this.salParams=null;
			return;
		}
		this.salParams=strValue;
	}
	
	/**
	* 调用参数 [非空]      
	**/
	public void setSalParams(String salParams){
		this.salParams = salParams;
		this.setSeted(F.salParams);
	}
	
	
	
	
	/*******************************返回数据**********************************/	
	/**
	* 返回数据 [非空]      
	**/
	public String getSalReturn(){
		if(this.salReturn!=null){
			return this.salReturn;
		}
		return this.salReturn;
	}
	/**
	* 获取返回数据格式化(toString)
	**/
	public String getSalReturn$(){
		String strValue="";
		 strValue=Utils.string(this.getSalReturn());
	 	 return strValue;
	}
	/**
	* 根据返回数据反格式化
	**/
	public void setSalReturn$(String strValue){
		if(Utils.empty(strValue)){
			this.salReturn=null;
			return;
		}
		this.salReturn=strValue;
	}
	
	/**
	* 返回数据 [非空]      
	**/
	public void setSalReturn(String salReturn){
		this.salReturn = salReturn;
		this.setSeted(F.salReturn);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getSalInvokeTime(){
		if(this.salInvokeTime!=null){
			return this.salInvokeTime;
		}
		return this.salInvokeTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getSalInvokeTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSalInvokeTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setSalInvokeTime$(String strValue){
		if(Utils.empty(strValue)){
			this.salInvokeTime=null;
			return;
		}
	 	this.salInvokeTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setSalInvokeTime(Date salInvokeTime){
		this.salInvokeTime = salInvokeTime;
		this.setSeted(F.salInvokeTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:默认    
	**/
	public Short getSalStatus(){
		if(this.salStatus!=null){
			return this.salStatus;
		}
		return this.salStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSalStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSalStatus()),"1"))
			strValue=Utils.string("默认");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSalStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.salStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"默认"))
		 	this.salStatus=Utils.parseShort("1");
	}
	
	/**
	* 状态 [非空]   1:默认    
	**/
	public void setSalStatus(Short salStatus){
		this.salStatus = salStatus;
		this.setSeted(F.salStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvApiLog.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvApiLog.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvApiLog.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvApiLog.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvApiLog.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvApiLog.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvApiLog.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvApiLog.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvApiLog.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvApiLog.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvApiLog.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvApiLog.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvApiLog.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M salId(Object salId){if(proxy)return proxy().salId(salId);  this.put("salId", salId);return this;};
	 	/** and sal_id is null */
 		public M salIdNull(){if(proxy)return proxy().salIdNull();if(this.get("salIdNot")==null)this.put("salIdNot", "");this.put("salId", null);return this;};
 		/** not .... */
 		public M salIdNot(){if(proxy)return proxy().salIdNot();this.put("salIdNot", "not");return this;};
 		public M salIdNotNull(){if(proxy)return proxy().salIdNotNull();this.put("salIdNot", "not");this.put("salId", null);return this;};
 		public M salIdNot(Object salId){if(proxy)return proxy().salIdNot(salId);this.put("salIdNot", "not");this.put("salId", salId);return this;};
		/** and sal_id <= ? */
		public M salIdMin(Object min){if(proxy)return proxy().salIdMin(min);this.put("salIdMin", min);return this;};
		/** and sal_id >= ? */
		public M salIdMax(Object max){if(proxy)return proxy().salIdMax(max);this.put("salIdMax", max);return this;};
		public M salIdIn(String ids){
			if(proxy)return proxy().salIdIn(ids);  this.put("salIdIn", ids);return this;
		};	
		public M salClient$on(SrvApiClient.M value){if(proxy)return proxy().salClient$on(value);this.put("SalClient", value);value.put("on", "sal_client");return this;};
		/** 调用应用 [非空] [SrvApiClient]      **/
		public M salClient(Object salClient){if(proxy)return proxy().salClient(salClient);  this.put("salClient", salClient);return this;};
	 	/** and sal_client is null */
 		public M salClientNull(){if(proxy)return proxy().salClientNull();if(this.get("salClientNot")==null)this.put("salClientNot", "");this.put("salClient", null);return this;};
 		/** not .... */
 		public M salClientNot(){if(proxy)return proxy().salClientNot();this.put("salClientNot", "not");return this;};
 		public M salClientNotNull(){if(proxy)return proxy().salClientNotNull();this.put("salClientNot", "not");this.put("salClient", null);return this;};
 		public M salClientNot(Object salClient){if(proxy)return proxy().salClientNot(salClient);this.put("salClientNot", "not");this.put("salClient", salClient);return this;};
		public M salClientIn(String ids){
			if(proxy)return proxy().salClientIn(ids);  this.put("salClientIn", ids);return this;
		};	
		public M salApi$on(SrvApi.M value){if(proxy)return proxy().salApi$on(value);this.put("SalApi", value);value.put("on", "sal_api");return this;};
		/** 调用API [非空] [SrvApi]     select * from srv_api where 1=1 **/
		public M salApi(Object salApi){if(proxy)return proxy().salApi(salApi);  this.put("salApi", salApi);return this;};
	 	/** and sal_api is null */
 		public M salApiNull(){if(proxy)return proxy().salApiNull();if(this.get("salApiNot")==null)this.put("salApiNot", "");this.put("salApi", null);return this;};
 		/** not .... */
 		public M salApiNot(){if(proxy)return proxy().salApiNot();this.put("salApiNot", "not");return this;};
 		public M salApiNotNull(){if(proxy)return proxy().salApiNotNull();this.put("salApiNot", "not");this.put("salApi", null);return this;};
 		public M salApiNot(Object salApi){if(proxy)return proxy().salApiNot(salApi);this.put("salApiNot", "not");this.put("salApi", salApi);return this;};
		/** 调用参数 [非空]       **/
		public M salParams(Object salParams){if(proxy)return proxy().salParams(salParams);  this.put("salParams", salParams);return this;};
	 	/** and sal_params is null */
 		public M salParamsNull(){if(proxy)return proxy().salParamsNull();if(this.get("salParamsNot")==null)this.put("salParamsNot", "");this.put("salParams", null);return this;};
 		/** not .... */
 		public M salParamsNot(){if(proxy)return proxy().salParamsNot();this.put("salParamsNot", "not");return this;};
 		public M salParamsNotNull(){if(proxy)return proxy().salParamsNotNull();this.put("salParamsNot", "not");this.put("salParams", null);return this;};
 		public M salParamsNot(Object salParams){if(proxy)return proxy().salParamsNot(salParams);this.put("salParamsNot", "not");this.put("salParams", salParams);return this;};
		/** 返回数据 [非空]       **/
		public M salReturn(Object salReturn){if(proxy)return proxy().salReturn(salReturn);  this.put("salReturn", salReturn);return this;};
	 	/** and sal_return is null */
 		public M salReturnNull(){if(proxy)return proxy().salReturnNull();if(this.get("salReturnNot")==null)this.put("salReturnNot", "");this.put("salReturn", null);return this;};
 		/** not .... */
 		public M salReturnNot(){if(proxy)return proxy().salReturnNot();this.put("salReturnNot", "not");return this;};
 		public M salReturnNotNull(){if(proxy)return proxy().salReturnNotNull();this.put("salReturnNot", "not");this.put("salReturn", null);return this;};
 		public M salReturnNot(Object salReturn){if(proxy)return proxy().salReturnNot(salReturn);this.put("salReturnNot", "not");this.put("salReturn", salReturn);return this;};
		/** 添加时间 [非空]       **/
		public M salInvokeTime(Object salInvokeTime){if(proxy)return proxy().salInvokeTime(salInvokeTime);  this.put("salInvokeTime", salInvokeTime);return this;};
	 	/** and sal_invoke_time is null */
 		public M salInvokeTimeNull(){if(proxy)return proxy().salInvokeTimeNull();if(this.get("salInvokeTimeNot")==null)this.put("salInvokeTimeNot", "");this.put("salInvokeTime", null);return this;};
 		/** not .... */
 		public M salInvokeTimeNot(){if(proxy)return proxy().salInvokeTimeNot();this.put("salInvokeTimeNot", "not");return this;};
 		public M salInvokeTimeNotNull(){if(proxy)return proxy().salInvokeTimeNotNull();this.put("salInvokeTimeNot", "not");this.put("salInvokeTime", null);return this;};
 		public M salInvokeTimeNot(Object salInvokeTime){if(proxy)return proxy().salInvokeTimeNot(salInvokeTime);this.put("salInvokeTimeNot", "not");this.put("salInvokeTime", salInvokeTime);return this;};
 		/** and sal_invoke_time >= ? */
 		public M salInvokeTimeStart(Object start){if(proxy)return proxy().salInvokeTimeStart(start);this.put("salInvokeTimeStart", start);return this;};			
 		/** and sal_invoke_time <= ? */
 		public M salInvokeTimeEnd(Object end){if(proxy)return proxy().salInvokeTimeEnd(end);this.put("salInvokeTimeEnd", end);return this;};
		/** 状态 [非空]   1:默认     **/
		public M salStatus(Object salStatus){if(proxy)return proxy().salStatus(salStatus);  this.put("salStatus", salStatus);return this;};
	 	/** and sal_status is null */
 		public M salStatusNull(){if(proxy)return proxy().salStatusNull();if(this.get("salStatusNot")==null)this.put("salStatusNot", "");this.put("salStatus", null);return this;};
 		/** not .... */
 		public M salStatusNot(){if(proxy)return proxy().salStatusNot();this.put("salStatusNot", "not");return this;};
 		public M salStatusNotNull(){if(proxy)return proxy().salStatusNotNull();this.put("salStatusNot", "not");this.put("salStatus", null);return this;};
 		public M salStatusNot(Object salStatus){if(proxy)return proxy().salStatusNot(salStatus);this.put("salStatusNot", "not");this.put("salStatus", salStatus);return this;};
		public M salStatusIn(String ids){
			if(proxy)return proxy().salStatusIn(ids);  this.put("salStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有API日志 **/
		public @api List<SrvApiLog> list(Integer size){			
			return getSrvApiLogList(this,size);
		}
		/** 获取API日志分页 **/
		public @api Page<SrvApiLog> page(Integer page,Integer size){			
			return getSrvApiLogPage(page, size , this);
		}
		/** 根据查询条件取API日志 **/
		public @api SrvApiLog get(){			
			return getSrvApiLog(this);
		}
		/** 获取API日志数 **/
		public @api Long count(){			
			return getSrvApiLogCount(this);
		}
		/** 获取API日志表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvApiLogEval(strEval,this);
		}
		/** 获取API日志统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvApiLogStats(this,sumKey,groupKey,dateType);
		}
		/** 获取API日志统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvApiLogStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvApiLog(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvApiLog(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String salId="salId";
		/** 调用应用 [非空] [SrvApiClient]      **/
		public final static @type(Long.class)  String salClient="salClient";
		/** 调用API [非空] [SrvApi]     select * from srv_api where 1=1 **/
		public final static @type(String.class)  String salApi="salApi";
		/** 调用参数 [非空]       **/
		public final static @type(String.class) @like String salParams="salParams";
		/** 返回数据 [非空]       **/
		public final static @type(String.class) @like String salReturn="salReturn";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String salInvokeTime="salInvokeTime";
	 	/** and sal_invoke_time >= ? */
 		public final static @type(Date.class) String salInvokeTimeStart="salInvokeTimeStart";
 		/** and sal_invoke_time <= ? */
 		public final static @type(Date.class) String salInvokeTimeEnd="salInvokeTimeEnd";
		/** 状态 [非空]   1:默认     **/
		public final static @type(Short.class)  String salStatus="salStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		salId("sal_id"),
		salClient("sal_client"),
		salApi("sal_api"),
		salParams("sal_params"),
		salReturn("sal_return"),
		salInvokeTime("sal_invoke_time"),
		salStatus("sal_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取API日志数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvApiLog.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvApiLog.getSrvApiLog(params);
			else
				value = SrvApiLog.getSrvApiLogList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvApiLog.where().salId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvApiLog.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSalId());
		Utils.fms(map,simple?"id":"salId",this.getSalId(),this.getSalId$());
		Utils.fms(map,simple?"client":"salClient",this.getSalClient(),this.getSalClient$());
 		if(!Utils.empty(this.getSalApi())){
 			Utils.fms(map,simple?"api":"salApi",this.getSalApi().replace("#",""),this.getSalApi$());
	 		List<Map> list = SrvApi.query(null,256,Utils.add("saIdIn",this.getSalApi().replace("#","")),false);
	 		Map<String,Map> mapping = new HashMap();
	 		for(Map m:list)mapping.put(""+m.get("key"), m);
	 		List<Map> newList = new ArrayList();
	 		for(String itm:this.getSalApi().replace("#","").split(",")){
	 			if(itm.equals("0"))continue;
	 			newList.add(mapping.get(itm));
	 		}
	 		map.put((simple?"api":"salApi")+"$list",newList);
 		}
		Utils.fms(map,simple?"params":"salParams",this.getSalParams(),this.getSalParams$());
		Utils.fms(map,simple?"return":"salReturn",this.getSalReturn(),this.getSalReturn$());
		Utils.fms(map,simple?"invokeTime":"salInvokeTime",this.getSalInvokeTime(),this.getSalInvokeTime$());
		Utils.fms(map,simple?"status":"salStatus",this.getSalStatus(),this.getSalStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("salId",this.getSalId());
		map.put("salClient",this.getSalClient());
		map.put("salApi",this.getSalApi());
		map.put("salParams",this.getSalParams());
		map.put("salReturn",this.getSalReturn());
		map.put("salInvokeTime",this.getSalInvokeTime());
		map.put("salStatus",this.getSalStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvApiLog fromMap(Map map){
		SrvApiLog srvApiLog = new SrvApiLog();
		srvApiLog.salId = Utils.parseLong(map.get("salId"));
		srvApiLog.salClient = Utils.parseLong(map.get("salClient"));
		srvApiLog.salApi = Utils.parseString(map.get("salApi"));
		srvApiLog.salParams = Utils.parseString(map.get("salParams"));
		srvApiLog.salReturn = Utils.parseString(map.get("salReturn"));
		srvApiLog.salInvokeTime = Utils.parseDate(map.get("salInvokeTime"));
		srvApiLog.salStatus = Utils.parseShort(map.get("salStatus"));
		return srvApiLog;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvApiLog old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/20088256421631277809.png";
	}
	public static String getIconfont(){
		return "icon-liebiao1";
	}
	public static enum ACT{
		列表,详情
	};
	public static String getUrl(ACT act,SrvApiLog.M params){
		if(params==null)params=new SrvApiLog.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/api/apilog.edit.html?";
		if(params.get("salId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("salId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/api/apilog.html?1=1";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.salId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvApiLog.ACT act,SrvApiLog.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvApiLog.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvApiLog.ACT act,SrvApiLog.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvApiLog.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvApiLogDao getSrvApiLogDao(){
		return Utils.getBean("srvApiLogDao");
	};
	
}